#!/bin/sh
################################################################
################################################################
cur_dir=$(cd `dirname $0`; pwd)
echo "cur_dir:$cur_dir"
conf_file=$cur_dir/app.conf
hostname=`hostname`
tmp_dir=`cat $conf_file|grep ${hostname}.ops_dir|awk -F "=" '{print $2}'`
jar_dir=`cat $conf_file|grep ${hostname}.jar_dir|awk -F "=" '{print $2}'`
ops_jar_dir=`cat $conf_file|grep ${hostname}.ops_jar_dir|awk -F "=" '{print $2}'`
ops=$ops_jar_dir/ops.jar.1
ops_node_file="$tmp_dir/ops.node"
JAVA=java
ops_conf="/tmp/ops.conf"
echo "                                                                                  ">$ops_conf
echo "cd /app/build/capp/docker                                                         ">>$ops_conf
echo "if [[ -f \"/tmp/db.tar.gz\" ]];then                                               ">>$ops_conf
echo "    rm -rf db/db.tar.gz                                                           ">>$ops_conf
echo "    mv /tmp/db.tar.gz db/                                                         ">>$ops_conf
echo "fi                                                                                ">>$ops_conf

echo "if [[ -f \"/tmp/app-3.2.0.jar\" ]];then                                           ">>$ops_conf
echo "    rm -rf app/app.jar                                                            ">>$ops_conf
echo "    mv /tmp/app-3.2.0.jar app/app.jar                                             ">>$ops_conf
echo "fi                                                                                ">>$ops_conf
echo "ls -rtl /app/build/capp/docker                                                    ">>$ops_conf


########################################### build docker image ###############################
echo "sh build.sh                                   ">>$ops_conf
echo "docker images|grep capp|grep 3.2.0            ">>$ops_conf


########################################### demo ###############################
echo "docker images|grep capp|grep 3.2.0            ">>$ops_conf
echo "docker-compose down                           ">>$ops_conf
echo "rm -rf /app/dapp                              ">>$ops_conf
echo "docker-compose up -d                          ">>$ops_conf

########################################### upload docker image ###############################
echo "exit 0                                                                              ">>$ops_conf
echo "nohup docker push registry.cn-hangzhou.aliyuncs.com/lank/mysql:capp_db_3.2.0 &      ">>$ops_conf
echo "nohup docker push registry.cn-hangzhou.aliyuncs.com/lank/app:capp_app_3.2.0 &       ">>$ops_conf
echo "nohup docker push registry.cn-hangzhou.aliyuncs.com/lank/nginx:capp_nginx_3.2.0 &   ">>$ops_conf

########################################### release docker image ###############################
echo "rm -rf dockerimage                           ">>$ops_conf
echo "mkdir -p dockerimage                         ">>$ops_conf
echo "cd dockerimage                               ">>$ops_conf
echo "docker save -o image-capp-db.tar.gz     registry.cn-hangzhou.aliyuncs.com/lank/mysql:capp_db_3.2.0     ">>$ops_conf
echo "docker save -o image-capp-app.tar.gz    registry.cn-hangzhou.aliyuncs.com/lank/app:capp_app_3.2.0      ">>$ops_conf
echo "docker save -o image-capp-nginx.tar.gz  registry.cn-hangzhou.aliyuncs.com/lank/nginx:capp_nginx_3.2.0  ">>$ops_conf
echo "rm -rf /opt/website/release/dapp/image*.tar.gz              ">>$ops_conf
echo "mv image*.gz /opt/website/release/dapp                      ">>$ops_conf
echo "chmod -R 777 /opt/website/release                           ">>$ops_conf
echo "ls -rtl /opt/website/release/dapp                           ">>$ops_conf
echo "exit 0                                                      ">>$ops_conf

#xi me /Users/lankl/IdeaProjects/dtAsset/docker/db/db.tar.gz
xi me /Users/lankl/IdeaProjects/dtAsset/dtAsset/target/app-3.2.0.jar


$JAVA  -jar $ops -e action -n $ops_node_file -c $ops_conf

exit 0








